package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> getListAll() {
        return nursingLevelMapper.getAll();
    }

    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto, nursingLevel);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public PageResponse<NursingLevelVo> getListByPage(String name, Integer page, Integer pageSize, Integer status) {
        PageHelper.startPage(page, pageSize);
        Page<NursingLevelVo> pageList = nursingLevelMapper.getBage(name,status);
        return PageResponse.of(pageList, NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo getById(Integer id) {
        return nursingLevelMapper.selectById(id);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto, nursingLevel);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void delete(Integer id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        nursingLevelMapper.updateStatus(id,status);
    }
}
